package com.leyou.search.pojo;

import java.util.Map;

public class SearchRequest {

    private String key; // 搜索的关键字
    private Integer page;   // 当前页

    private String sortBy; // 排序字段
    private Boolean descending; // 是否降序

    // 过滤条件
    private Map<String,String> filter;

    private static final Integer DEFAULT_SIZE = 20; // 每页默认条数
    private static final Integer DEFAULT_PAGE = 1;  // 默认第一页


    public Map<String, String> getFilter() {
        return filter;
    }

    public void setFilter(Map<String, String> filter) {
        this.filter = filter;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public Integer getPage() {
        // 获取页码时需要设置一些校验,如果不传，默认为第一页
        if (this.page == null) {
            return DEFAULT_PAGE;
        }
        return Math.max(DEFAULT_PAGE, page);
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getSize() {

        return DEFAULT_SIZE;
    }

    public String getSortBy() {
        return sortBy;
    }

    public void setSortBy(String sortBy) {
        this.sortBy = sortBy;
    }

    public Boolean getDescending() {
        return descending;
    }

    public void setDescending(Boolean descending) {
        this.descending = descending;
    }
}
